﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using CloudApiServer.Services;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;


namespace CloudApiServer.Controllers
{
    
    /// <summary>
    /// 山东进销存接口控制器
    /// </summary>
    [RoutePrefix("hsu/mihs")]
    public class FsiApiShandongJxcController : ApiController
    {
        private readonly SignInSignOutService _signInSignOuService;
        private readonly GoodsService _goodsService;

        public FsiApiShandongJxcController()
        {
            _signInSignOuService = new SignInSignOutService();
            _goodsService = new GoodsService();
        }
        
        /*接口*/
        /// <summary>
        /// 医保接口没找到的统一接口返回
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [HttpPost]
        public IHttpActionResult FsiNotFound(HttpRequestMessage request)
        {
            string url = request.RequestUri.ToString();
            string Method = request.Method.ToString();
            string Errnum = LogHelper.GetErrornumber();
            try
            {
                if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                {
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参为空！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
                else
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignIn>>(request.Content.ReadAsStringAsync().Result);
                    string infno = fsiRequest.infno;
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加！当前请求的接口号：{infno},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
            }
            catch (JsonReaderException)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参格式不正确！服务端无法正常反序列化！请检查入参是否为Json格式！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);

            }
            catch (Exception ex)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且服务端程序处理异常！请联系管理员排查！当前异常提示：{ex.Message},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);
            }
        }
        /*接口*/
        /// <summary>
        /// 医保接口没找到的统一接口返回
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("MihsServlet")]
        public IHttpActionResult MihsServletForGet(HttpRequestMessage request)
        {
            string url = request.RequestUri.ToString();
            string Method = request.Method.ToString();
            string Errnum = LogHelper.GetErrornumber();
            try
            {
                if (string.IsNullOrEmpty(request.Content.ReadAsStringAsync().Result))
                {
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参为空！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
                else
                {
                    var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignIn>>(request.Content.ReadAsStringAsync().Result);
                    string infno = fsiRequest.infno;
                    FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                    {
                        infcode = -1,
                        err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加！当前请求的接口号：{infno},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                    };
                    return Json(FsiHeader);
                }
            }
            catch (JsonReaderException)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且入参格式不正确！服务端无法正常反序列化！请检查入参是否为Json格式！当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);

            }
            catch (Exception ex)
            {
                FsiHeader<outputsignInOut> FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请求的接口【{url}】方法【{Method}】暂未添加且服务端程序处理异常！请联系管理员排查！当前异常提示：{ex.Message},当前请求入参：" + request.Content.ReadAsStringAsync().Result
                };
                return Json(FsiHeader);
            }
        }

        /// <summary>
        /// 山东地纬接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [Route("MihsServlet")]
        [HttpPost]
        public async Task<IHttpActionResult> MihsServlet(HttpRequestMessage request)
        {
            try
            {
                if (FsiDatainfo.stateShandongJxcApi == false)
                {
                    throw new Exception("该接口已被控制台停用！请联系管理员！");
                }
                var fsiRequestabc = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignIn>>(request.Content.ReadAsStringAsync().Result);
                Console.WriteLine($"山东进销存入参:{request.Content.ReadAsStringAsync().Result}");
                string infno = fsiRequestabc.info;
                if (string.IsNullOrEmpty(infno))
                {
                    throw new Exception($"传入的参数有误!未获取到接口号infno,请检查入参！当前入参：{request.Content.ReadAsStringAsync().Result}");
                }
                string connectionString = $"Database={ApiDatainfo.mysqlDatabase};Data Source={ApiDatainfo.mysqlUrl};Port={ApiDatainfo.mysqlPost};UserId={ApiDatainfo.mysqlUser};Password={ApiDatainfo.mysqlPwd};Charset=utf8mb4;TreatTinyAsBoolean=false;Allow User Variables=True";
                switch (infno)
                {
                    case "9001":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignInShandong>>(request.Content.ReadAsStringAsync().Result);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var signin =
                                    await _signInSignOuService.SignInShandongAsync(fsiRequest, this.GetType().Name);
                                var FsiHeader = new FsiHeader<outputsignInOutShandong>
                                {
                                    output = signin,
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid =
                                        $"430000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}" 
                                };
                                return Json(FsiHeader);
                            }
                    case "9002":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputSignOutShandong>>(request.Content.ReadAsStringAsync().Result);
                                var siginout =
                                    await _signInSignOuService.SignOutShandongAsync(fsiRequest, this.GetType().Name);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var FsiHeader = new FsiHeader<outputsignInOutShandong>
                                {
                                    output = siginout,
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid =
                                        $"430000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}" 
                                };
                                return Json(FsiHeader);
                            }
                    case "3501":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsUpload>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsUpload(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsUpload返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    case "3502":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsUpdate>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsUpdate(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsUpdate返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }
                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    case "3503":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsBuy>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsBuy(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsBuy返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    case "3504":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsBuy>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsBuyReturn(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsBuyReturn返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    case "3505":
                        try
                        {
                            var fsiRequest =
                                JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSell>>(request.Content
                                    .ReadAsStringAsync().Result);
                            string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                            Random rnd = new Random();
                            DateTime dateTime = DateTime.Now;
                            var flag = await _goodsService.GoodsSell(fsiRequest, this.GetType().Name);
                            if (flag == true)
                            {
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = 0,
                                    warn_msg = null,
                                    cainfo = null,
                                    err_msg = "success",
                                    refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    signtype = null,
                                    respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                    inf_refmsgid = $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                };
                                return Json(FsiHeader);
                            }
                            else
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg =
                                        $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsSell返回的状态为{flag}！"
                                };
                                return Json(FsiHeader);
                            }
                        }
                        catch (Exception ex)
                        {
                            string Errnum = LogHelper.GetErrornumber();
                            var FsiHeader = new FsiHeader<outputsignInOut>
                            {
                                infcode = -1,
                                err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                            };
                            return Json(FsiHeader);
                        }
                    case "3506":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSellList>>(request.Content.ReadAsStringAsync().Result);
                                //var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSell>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsSellReturnList(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsSellReturn返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    case "3507":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsInfoDelete>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsInfoDelete(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsInfoDelete返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }
                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    case "3568":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodStocks>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsStocks(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsInfoDelete返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    case "3569":
                       try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsInformationInfo>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsInformationInfo(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsInfoDelete返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }

                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    case "3599":
                        try
                            {
                                var fsiRequest = JsonConvert.DeserializeObject<FsiRequestHeader<InputGoodsSellTracInfo>>(request.Content.ReadAsStringAsync().Result);
                                string fsiadmvs = fsiRequest.mdtrtarea_admvs.Substring(0, 2);
                                Random rnd = new Random();
                                DateTime dateTime = DateTime.Now;
                                var flag = await _goodsService.GoodsSellTracInfo(fsiRequest, this.GetType().Name);
                                if (flag == true)
                                {
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = 0,
                                        warn_msg = null,
                                        cainfo = null,
                                        err_msg = "success",
                                        refmsg_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        signtype = null,
                                        respond_time = dateTime.ToString("yyyyMMddHHmmssfff"),
                                        inf_refmsgid =
                                            $"{fsiadmvs}0000{dateTime.ToString("yyyyMMddHHmmssfff")}{rnd.Next(1000000, 10000000).ToString()}"
                                    };
                                    return Json(FsiHeader);
                                }
                                else
                                {
                                    string Errnum = LogHelper.GetErrornumber();
                                    var FsiHeader = new FsiHeader<outputsignInOut>
                                    {
                                        infcode = -1,
                                        err_msg =
                                            $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！调用进销存上传服务GoodsService.GoodsInfoDelete返回的状态为{flag}！"
                                    };
                                    return Json(FsiHeader);
                                }
                            }
                            catch (Exception ex)
                            {
                                string Errnum = LogHelper.GetErrornumber();
                                var FsiHeader = new FsiHeader<outputsignInOut>
                                {
                                    infcode = -1,
                                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}"
                                };
                                return Json(FsiHeader);
                            }
                    default:
                        throw new Exception($"[山东医保自定义接口]接口号{infno}未被定义，请检查入参或联系管理员！");
                }
            }
            catch (Exception ex)
            {
                string Errnum = LogHelper.GetErrornumber();
                var FsiHeader = new FsiHeader<outputsignInOut>
                {
                    infcode = -1,
                    err_msg = $"[{Errnum}]调用山东医保进销存自定义服务失败！请检查！错误内容：{ex.Message} 异常来源：{ex.StackTrace}" 
                };
                return Json(FsiHeader);
            }
        }

    }
}
